package com.bbx.taxi.client.Bean.Attribute;

import java.util.ArrayList;
import java.util.Date;

import com.bbx.api.sdk.model.official.passanger.Return.OrderList.OfficialOrderList;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Extra.MainMsg;
import com.bbx.taxi.client.Util.DateFormat;

/**
 * 修改界面的信息临时存储
 */
public class ChangeAttribute {
	/**
	 * 修改界面内容填写监听
	 *
	 */
	public interface OnContentFillingListener{
		 /**
		 * 修改界面内容填写监听方法
		 */
		public void onContentFilling();
	};
	public  OnContentFillingListener mOnContentFillingListener;
	public  void setOnContentFillingListener(OnContentFillingListener hOnContentFillingListener){
		mOnContentFillingListener=hOnContentFillingListener;
	}
	
	public static final int REQUEST_CODE_PERSON = 0;
	public static final int REQUEST_CODE_PERSON2 = 1;
	public static final int REQUEST_CODE_START_ADDRESS = 2;
	public static final int REQUEST_CODE_END_ADDRESS = 3;
	public static final int REQUEST_CODE_PLANE = 4;
	public static final int REQUEST_CODE_MESSAGE = 5;
	public static final int REQUEST_CODE_GOODS = 6;
	public static final int REQUEST_CODE_EDITNAME = 7;
	private String time="现在出发";
	private String st_start_name="";
	private String st_start_city="";
	private String st_start_address="";
	private double st_start_longitude;
	private double st_start_latitude;
	private String st_end_name="";
	private String st_end_city="";
	private String st_end_address="";
	private double st_end_longitude;
	private double st_end_latitude;
	private String name="本人";
	private String tel;
	private String name2="";
	private String tel2;
	private String message_kj = "";
	private String message_pc = "";
	private String message_bc = "";
	private int goods_weight;//物品重量
	private int goods_volume;//物品体积
	private int count;
	/**包车数量*/
	private int count_bc = 1;
	/**判断是否是航班，0为不是，1为接机，2个送机*/
	private int plane_status;
	private String plane_numble;
	/**判断是否勾选条款*/
	private boolean  isCBclause=true;
	private int is_mutiple_oncar=0;
	private static ChangeAttribute change;

	public static ChangeAttribute getInstance() {
		if (change == null) {
			change = new ChangeAttribute();
			return change;

		} else
			return change;
	}
	public void setTime(String time){
		this.time=time;
		onContentFilling();
	}
	public String getTime(){
		return time;
	}
	public void setStartName(String st_start_name){
		this.st_start_name=st_start_name;
		onContentFilling();
	}
	public String getStartName(){
		return st_start_name;
	}
	public void setStartCity(String st_start_city){
		this.st_start_city=st_start_city;
	}
	public String getStartCity(){
		try{
			if (st_start_city == null || st_start_city.equals("")||st_start_city.contains(Value.CITY_SPILT)
					||st_start_city.contains("\t")||st_start_city.contains("-")) {
				if(st_start_name.contains(Value.CITY_SPILT)){
					st_start_city = st_start_name.substring(0,
							st_start_name.indexOf(Value.CITY_SPILT));
				}
				else if(st_start_name.contains("\t")){
					st_start_city = st_start_name.substring(0,
							st_start_name.indexOf("\t"));
				}
				else if(st_start_name.contains("-")){
					st_start_city = st_start_name.substring(0,
							st_start_name.indexOf("-"));
				}
				else{
					st_start_city=st_start_name;
				}
			}
		}
		catch(Exception e){}
		return st_start_city;
	}
	public void setStartAddress(String st_start_address){
		this.st_start_address=st_start_address;
		onContentFilling();
	}
	public String getStartAddress(){
		return st_start_address;
	}
	public void setStartLongitude(double st_start_longitude){
		this.st_start_longitude=st_start_longitude;
		onContentFilling();
	}
	public double getStartLongitude(){
		return st_start_longitude;
	}
	
	public void setStartLatitude(double st_start_latitude){
		this.st_start_latitude=st_start_latitude;
		onContentFilling();
	}
	public double getStartLatitude(){
		return st_start_latitude;
	}
	
	
	
	public void setEndName(String st_end_name){
		this.st_end_name=st_end_name;
		onContentFilling();
	}
	public String getEndName(){
		return st_end_name;
	}

	public void setEndCity(String st_end_city){
		this.st_end_city=st_end_city;
	}
	public String getEndCity(){
		try {
			if (st_end_city == null || st_end_city.equals("")||st_end_city.contains(Value.CITY_SPILT)
					||st_end_city.contains("\t")||st_end_city.contains("-")) {
				if(st_end_name.contains(Value.CITY_SPILT)){
					st_end_city = st_end_name.substring(0,
							st_end_name.indexOf(Value.CITY_SPILT));
				}
				else if(st_end_name.contains("\t")){
					st_end_city = st_end_name.substring(0,
							st_end_name.indexOf("\t"));
				}
				else if(st_end_name.contains("-")){
					st_end_city = st_end_name.substring(0,
							st_end_name.indexOf("-"));
				}
				else{
					st_end_city=st_end_name;
				}

			}
		} catch (Exception e) {
		}

		return st_end_city;
	}
	public void setEndAddress(String st_end_address){
		this.st_end_address=st_end_address;
		onContentFilling();
	}
	public String getEndAddress(){
		return st_end_address;
	}
	public void setEndLongitude(double st_end_longitude){
		this.st_end_longitude=st_end_longitude;
		onContentFilling();
	}
	public double getEndLongitude(){
		return st_end_longitude;
	}
	
	public void setEndLatitude(double st_end_latitude){
		this.st_end_latitude=st_end_latitude;
		onContentFilling();
	}
	public double getEndLatitude(){
		return st_end_latitude;
	}
	public void setName(String name){
		this.name=name;
		onContentFilling();
	}
	public String getName(){
		return name;
	}
	public void setTel(String tel){
		this.tel=tel;
		onContentFilling();
	}
	public String getTel(){
		return tel;
	}
	
	public void setName2(String name2){
		this.name2=name2;
		onContentFilling();
	}
	public String getName2(){
		return name2;
	}
	public void setTel2(String tel2){
		this.tel2=tel2;
	}
	public String getTel2(){
		return tel2;
	}
	
	public void setMessage_KJ(String message) {
		this.message_kj = message;
//		onContentFilling();
	}

	public String getMessage_KJ() {
		return message_kj;
	}
	public void setMessage_PC(String message) {
		this.message_pc = message;
		onContentFilling();
	}

	public String getMessage_PC() {
		return message_pc;
	}
	public void setMessage_BC(String message) {
		this.message_bc = message;
		onContentFilling();
	}
	public String getMessage_BC() {
		return message_bc;
	}
	public void setGoodsWeight(int goods_weight){
		this.goods_weight=goods_weight;
//		onContentFilling();
	}
	public int getGoodsWeight(){
		return goods_weight;
	}
	public void setGoodsVolume(int goods_volume){
		this.goods_volume=goods_volume;
//		onContentFilling();
	}
	public int getGoodsVolume(){
		return goods_volume;
	}
	public void setCount(int count){
		this.count=count;
		onContentFilling();
	}
	public int getCount(){
		return count;
	}
	public void setCount_BC(int count_bc) {
		this.count_bc = count_bc;
		onContentFilling();
	}

	public int getCount_BC() {
		return count_bc;
	}
	public void setPlaneStatus(int plane_status){
		this.plane_status=plane_status;
		onContentFilling();
	}
	public int getPlaneStatus(){
		return plane_status;
	}
	public void setPlaneNumble(String plane_numble){
		this.plane_numble=plane_numble;
		onContentFilling();
	}
	public String getPlaneNumble(){
		return plane_numble;
	}
	public void setIsCBclause(boolean  isCBclause) {
		this.isCBclause = isCBclause;
		onContentFilling();
	}

	public boolean  getIsCBclause() {
		return isCBclause;
	}
	public void setIs_mutiple_oncar(int  is_mutiple_oncar) {
		this.is_mutiple_oncar = is_mutiple_oncar;
	}
	public int getIs_mutiple_oncar() {
		return is_mutiple_oncar;
	}
	
	/**
	/**
	 * 交换起始位置
	 */
	public void onSwap(){
		StringBuffer[] sb_name = new StringBuffer[2];
		sb_name[0] = new StringBuffer(st_start_name + "");
		sb_name[1] = new StringBuffer(st_end_name + "");
		st_start_name = sb_name[1].toString();
		st_end_name = sb_name[0].toString();
		
		StringBuffer[] sb_city = new StringBuffer[2];
		sb_city[0] = new StringBuffer(st_start_city + "");
		sb_city[1] = new StringBuffer(st_end_city + "");
		st_start_city = sb_city[1].toString();
		st_end_city = sb_city[0].toString();
		
		StringBuffer[] sb_address = new StringBuffer[2];
		sb_address[0] = new StringBuffer(st_start_address + "");
		sb_address[1] = new StringBuffer(st_end_address + "");
		st_start_address = sb_address[1].toString();
		st_end_address = sb_address[0].toString();

		StringBuffer[] sb_longitude = new StringBuffer[2];
		sb_longitude[0] = new StringBuffer(st_start_longitude + "");
		sb_longitude[1] = new StringBuffer(st_end_longitude + "");
		st_start_longitude = Double.parseDouble(sb_longitude[1].toString());
		st_end_longitude =  Double.parseDouble(sb_longitude[0].toString());

		StringBuffer[] sb_latitude = new StringBuffer[2];
		sb_latitude[0] = new StringBuffer(st_start_latitude + "");
		sb_latitude[1] = new StringBuffer(st_end_latitude + "");
		st_start_latitude = Double.parseDouble(sb_latitude[1].toString());
		st_end_latitude = Double.parseDouble(sb_latitude[0].toString());
		onContentFilling();
	}
	/**
	 * 设置所有的属性
	 */
	public void setAttribute(OfficialOrderList mOfficialOrderList) {
		if(DateFormat.onDate_Long(mOfficialOrderList.getAppoint_time())>new Date().getTime()){
			change.setTime(DateFormat.onDateRemove_ss(mOfficialOrderList.getAppoint_time()));
		}
		else{
			change.setTime("现在出发");
		}
		change.setStartName(mOfficialOrderList.getOrderDetail().getStart().getAddress());
		change.setStartCity("");
		change.setStartLatitude(mOfficialOrderList.getOrderDetail().getStart()
				.getLocation().getLat());
		change.setStartLongitude(mOfficialOrderList.getOrderDetail().getStart()
				.getLocation().getLng());
		change.setEndName(mOfficialOrderList.getOrderDetail().getEnd().getAddress());
		change.setEndCity("");
		change.setEndLatitude(mOfficialOrderList.getOrderDetail().getEnd().getLocation()
				.getLat());
		change.setEndLongitude(mOfficialOrderList.getOrderDetail().getEnd().getLocation()
				.getLng());
		change.setTel(mOfficialOrderList.getOrderDetail().getStart().getPhone());
		change.setTel2(mOfficialOrderList.getOrderDetail().getEnd().getPhone());
		change.setName(mOfficialOrderList.getOrderDetail().getStart().getName());
		change.setName2(mOfficialOrderList.getOrderDetail().getEnd().getName());
		switch(Integer.parseInt(mOfficialOrderList.getOrder_type())){
		case Value.ORDER_TYPE_SN:
			change.setCount(1);
			change.setMessage_KJ(null);
			change.setMessage_PC(null);
			change.setMessage_BC(null);
			change.setCount_BC(1);
			break;
		case Value.ORDER_TYPE_KJ:
//			change.setCount(mOfficialOrderList.getOrderDetail().getCount());
			change.setMessage_KJ(mOfficialOrderList.getMessage());
			change.setMessage_PC(null);
			change.setMessage_BC(null);
			change.setCount_BC(1);
			break;
		case Value.ORDER_TYPE_PC:
//			change.setCount(mOfficialOrderList.getOrderDetail().getCount());
			change.setMessage_KJ(null);
			change.setMessage_PC(mOfficialOrderList.getMessage());
			change.setMessage_BC(null);
			change.setCount_BC(1);
			break;
		case Value.ORDER_TYPE_BC:
			change.setCount(1);
//			change.setCount_BC(mOfficialOrderList.getOrderDetail().getCount());
			change.setMessage_KJ(null);
			change.setMessage_PC(null);
			change.setMessage_BC(mOfficialOrderList.getMessage());
//			change.setIs_mutiple_oncar(mOfficialOrderList.getOrderDetail().getIs_mutiple_oncar());
			break;
		}	
		try {
//			change.setGoodsVolume(Integer.parseInt(mOfficialOrderList.getOrderDetail()
//					.getVolume()));
//			change.setGoodsWeight(Integer.parseInt(mOfficialOrderList.getOrderDetail()
//					.getWeight()));
//			change.setIs_mutiple_oncar(mOfficialOrderList.getOrderDetail().getIs_mutiple_oncar());
		} catch (Exception e) {
		}

	}

	/**
	 * 还原属性值
	 */
	public void onRestoreAttribute() {
		MyApplication mApplication = MyApplication.getInstance();
		change.setTime("现在出发");
		change.setStartName("");
		change.setStartCity("");
		change.setStartLatitude(0);
		change.setStartLongitude(0);
		change.setEndName("");
		change.setEndCity("");
		change.setEndLatitude(0);
		change.setEndLongitude(0);
		change.setTel(mApplication.getUserphone());
		change.setTel2("");
		change.setName(mApplication.getUserName());
		change.setName2("");
		change.setCount(1);
		change.setCount_BC(1);
		change.setGoodsVolume(0);
		change.setGoodsWeight(0);
		change.setMessage_KJ(null);
		change.setMessage_PC(null);
		change.setMessage_BC(null);
	}
	/**
	 * 调用内容填充监听方法，用来监听必选的内容是否全部填满
	 */
	public void onContentFilling(){
		if(mOnContentFillingListener!=null){
			mOnContentFillingListener.onContentFilling();
		}
	}
}
